package com.bignerdranch.android.ecar.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.bignerdranch.android.ecar.Bean.HomeBean;
import com.bignerdranch.android.ecar.R;

import java.util.List;

/**
 * Created by Administrator on 2016/7/18.
 */
public class HomeAdapter extends BaseAdapter {

    private LayoutInflater mInflater;
    private List<HomeBean> mData;
    private Context mContext;

    public HomeAdapter(Context context, List<HomeBean> data) {
        mContext = context;
        mData = data;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int position) {
        return mData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null){
            convertView = mInflater.inflate(R.layout.home_item,null);
        }
        ViewHolder holder = new ViewHolder();
        if (convertView.getTag()==null){
            holder.mTextView = (TextView) convertView.findViewById(R.id.news_title);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.mTextView.setText(mData.get(position).getTitle());

        return convertView;
    }

    private static class ViewHolder {
        private TextView mTextView;
    }
}
